package com.example.cpoopc.helloretrofit.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * ImgInfo数据结构
 * 
 * <br>Created 2014-8-21 下午3:14:34
 * @version  
 * @author   chenpeng		
 *
 * @see
 */
public class ImgInfo implements Parcelable{
    public long id;// 图片ID[必选]
//    public int column;// 所占格数(1,2,3)
    public int width;// 图片宽度[必选]
    public int height;// 图片高度[必选]
    public long size;// 字节数[必选]
    public String ext;// 图片文件实际格式：jpg，gif，png[必选]
    public String thumbUrl;
    
    
    
    public ImgInfo(String ext, String thumbUrl) {
        super();
        this.id = -1;
        this.ext = ext;
        this.thumbUrl = thumbUrl;
    }


    public ImgInfo(long id, int width, int height, long size, String ext, String thumbUrl) {
        super();
        this.id = id;
        this.width = width;
        this.height = height;
        this.size = size;
        this.ext = ext;
        this.thumbUrl = thumbUrl;
    }

    public static final Creator<ImgInfo> CREATOR = new Creator<ImgInfo>() {
        
        @Override
        public ImgInfo[] newArray(int size) {
            return new ImgInfo[size];
        }
        
        @Override
        public ImgInfo createFromParcel(Parcel source) {
            return new ImgInfo(source);
        }
    };
    
    private ImgInfo(Parcel source){
        id = source.readLong();
        width = source.readInt();
        height = source.readInt();
        size = source.readLong();
        ext = source.readString();
        thumbUrl = source.readString();
    }
    
    
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeInt(width);
        dest.writeInt(height);
        dest.writeLong(size);
        dest.writeString(ext);
        dest.writeString(thumbUrl);
    }
    
    public JSONObject toJsonObject() throws JSONException{
        JSONObject jb = new JSONObject();
        jb.put("id", id);
        jb.put("width", width);
        jb.put("height", height);
        jb.put("size", size);
        jb.put("ext", ext);
        jb.put("thumbUrl", thumbUrl);
        return jb;
        
    }
    
}
